package Engine.UIControl
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;
	
	import library.Function.Dict;

	public class UIMouse
	{
		public static const MOUSE_CURSOR_SYSTEM:int = 0;
		public static const MOUSE_CURSOR_NORMAL:int = 1;
		
		private static var mouseCursorDict:Dict = new Dict();
		private static var ins:UIMouse = null;
		private static var stage:Stage = null;
		
		private var _mouseCursor:Sprite = null;
		
		
		public function UIMouse()
		{
			
		}
		
		public static function addMouseCursorDict(type:int,msCursor:Sprite):void
		{
			mouseCursorDict[type] = msCursor;
		}
		
		public static function setMouseCursor(type:int):void
		{
			if(ins == null)
				ins = new UIMouse();
			if(type == MOUSE_CURSOR_SYSTEM)
			{
				ins.clean();
				Mouse.show();
			}
			Mouse.hide();
			if(!mouseCursorDict.has_key(type))
			{
				if(mouseCursorDict.has_key(MOUSE_CURSOR_NORMAL))
					ins.setCursor(MOUSE_CURSOR_NORMAL);
				else
				{
					ins.clean();
					Mouse.show();
				}
			}
			else
			{
				ins.setCursor(type);
			}
		}
		
		public static function show():void
		{
			Mouse.show();
			return;
			ins._mouseCursor.startDrag(true);
			stage.addChild(ins._mouseCursor);
		}
		
		public static function hide():void
		{
			Mouse.hide();
			return;
			ins._mouseCursor.stopDrag();
			stage.removeChild(ins._mouseCursor);
		}
		
		public static function setStage(st:Stage):void
		{
			stage = st;
		}
		
		public function clean():void
		{
			if(!this._mouseCursor)
				return;
			this._mouseCursor.stopDrag();
			stage.removeChild(this._mouseCursor);
			this._mouseCursor = null;
		}
		
		public function setCursor(type:int):void
		{
			this._mouseCursor = mouseCursorDict[type];
			this._mouseCursor.mouseEnabled = false;
			this._mouseCursor.mouseChildren = false;
			this._mouseCursor.startDrag(true);
			stage.addChild(this._mouseCursor);
		}
	}
}